home *** CD-ROM | disk | FTP | other *** search
/ Amoszine 6 / Amoszine 6 (Disk 2 of 2).adf / extra_source.lha / OTHER_SOURCE / _MAKEMASK.Amos / _MAKEMASK.amosSourceCode next >
Encoding:
AMOS Source Code  |  1992-02-26  |  7.0 KB  |  185 lines

  1. Screen Open 0,320,200,8,0 : Curs Off : Flash Off : Cls 0
  2. Palette 0,$F00,$F0,$F,$FFF
  3. Ink 0 : Bar 0,0 To 15,15
  4. Ink 1 : Bar 16,0 To 31,15
  5. Ink 2 : Bar 0,16 To 15,31
  6. Ink 3 : Bar 16,16 To 31,31
  7. Get Icon 1,0,0 To 32,32 : Make Icon Mask 
  8. _MAKEMASK[0,2,5,6,0,0,32,32,1]
  9. Pen 4 : Paper 0
  10. Locate 0,10 : Print 'A 4-colour icon...'
  11. 'prove that it worked... 
  12. Ink 4 : Bar 40,40 To 79,79
  13. Print '... a white block... (press a key)'
  14. Wait Key 
  15. Paste Icon 44,44,1
  16. Print '... with the icon masked in colour 2!'
  17.  
  18. Procedure _MAKEMASK[_SCREEN,_COLOUR,TEMP1,TEMP2,X1,Y1,X2,Y2,_ICON]
  19.  '
  20.  ' Version: 1.0   
  21.  '      By: ** Michael Sikorsky **  
  22.  '          (special thanks to ** Rich Helvey ** for the idea of using the
  23.  '           buffer screen to stop my amiga from crashing becasue of my 
  24.  '           inexperience with dirrect blitter access.)   
  25.  '  e-mail: sikorsky@bode.ee.ualberta.ca  
  26.  '    
  27.  ' Distribution:  This program is freely distributable.  All I ask is if
  28.  '                you make changes,improvements, or bug fixes (etc) that  
  29.  '                you mail me a new copy of the source.  Also somekind
  30.  '                of acknowledgment in your greetings/credits/manual/etc
  31.  '                would be appreciated, thanks. 
  32.  '  
  33.  ' Requirements:  none. 
  34.  '                              
  35.  '  Description:  Creates a Mask of any color for an Icon.  It is done
  36.  '                quickly at the expense of some memory needed for 2
  37.  '                extra temp screens that are only 2 color screens.  This 
  38.  '                procedure also is intended to also show how the logic of
  39.  '                mask making can be accomplished.  If direct use of the
  40.  '                blitter was employed then the need for the 2 extra screens
  41.  '                and the trouble with getting the mask data linear in  
  42.  '                memory would be eliminated.     
  43.  '                
  44.  '   Parameters:  _SCREEN=number of the screen where image data is. 
  45.  '                _COLOUR=number of the colour you want Masked. 
  46.  '                  TEMP1=number of first temporary screen. 
  47.  '                  TEMP2=number of second temporary screen.
  48.  '                (X1,Y1)=top left hand corner of image.
  49.  '                (X2,Y2)=bottom right hand corner of image.
  50.  '                  _ICON=number of the Icon that you want the mask for.
  51.  '
  52.  '        notes:  - TEMP1,TEMP2 screens are created (1 bitplane) so if these
  53.  '                  screens are defined elsewhere they will be deleted. 
  54.  '                - can be changed to work for Bob's easily. use Sprite Base()
  55.  '                  instead of Icon Base(). 
  56.  '                - will work for any number of colors as long as there are 
  57.  '                  no tricks like HAM going on... therefore it will mask out 
  58.  '                  colors on a EHB screen but not on a HAM screen (well it will
  59.  '                  but it may/may not work properly.)
  60.  '                    
  61.  '      Returns:   nothing. 
  62.  '
  63.  
  64. '******  Make The Mask.... 
  65.  
  66. _T_SCR=Screen
  67.  
  68.    WID=Screen Width : HIT=Screen Height
  69.  
  70.    Screen Open TEMP1,WID,HIT,2,Lowres : Screen Hide TEMP1 : Curs Off 
  71.    Screen Open TEMP2,WID,HIT,2,Lowres : Screen Hide TEMP2 : Curs Off 
  72.    Screen TEMP1 : SB1=Phybase(0)
  73.    Screen TEMP2 : Cls 0
  74.  
  75.    BPLEN=WID*HIT/8.0
  76.  
  77.    Screen _SCREEN : _NUM_OF_PLANES=Deek(Screen Base+$50)
  78.  
  79.    _COL$=Flip$(Bin$(_COLOUR,_NUM_OF_PLANES)-"%")
  80.  
  81.    '
  82.    ' the reasoning why I OR and NOT is this... I want the color that we are 
  83.    ' masking to contribute nothing to the mask.. ie. 0 or X=X... thats why
  84.    ' I have to NOT the "1" values... this ends up making the color we want to 
  85.    ' not contribute to the mask.... mike  
  86.    '  
  87.    ' ie. if you had a 4 color screen then that takes 2 bitplane's and say 
  88.    '     you wanted to mask out Color 1 (%01) --> 
  89.    '
  90.    '     bitplane 0:  bitplane 1:   Resultant Colors   Mask Should Be:  
  91.    '                                   on screen: 
  92.    '      0  1        0   0              0  1          1  0 
  93.    '      0  1        1   1              2  3          1  1   
  94.    '
  95.    '      therefore because Color 1 is represnted by %01 on the bitpalnes 
  96.    '      I want to do this --> (bitplane 1) OR (NOT(bitplane 0))=Mask
  97.    '  
  98.    '      bitplane 1:             NOT(bitplane0):       Mask:   
  99.    '  
  100.    '         0  0        OR           1  0           =  1  0   Correct. 
  101.    '         1  1                     1  0              1  1  
  102.    '
  103.  
  104.    For X=0 To _NUM_OF_PLANES-1
  105.       Copy Phybase(X),Phybase(X)+BPLEN To SB1
  106.       _VAL$=Mid$(_COL$,X+1,1)
  107.       If _VAL$="1"
  108.          ' Not  
  109.           Screen Copy TEMP1,0,0,WID,HIT To TEMP1,0,0,%110000
  110.       End If 
  111.       'or  
  112.       Screen Copy TEMP1,0,0,WID,HIT To TEMP2,0,0,%11100000
  113.    Next 
  114.    ' uncomment this if you want the not of the mask.
  115.    'NOT -- if want opposite mask
  116.    'Screen Copy temp2,0,0,WID,HIT To temp2,0,0,%110000
  117.  
  118. '****** Copy Mask into the Icon... 
  119. '   Screen To Front TEMP1
  120.    Screen TEMP1
  121.    Cls 0 : Rem very important .. ie. so that extra data copied is just blank  
  122. '
  123. ' copy the screen data to be used as the mask to (0,0) 
  124. '
  125.    Screen Copy TEMP2,X1,Y1,X2,Y2 To TEMP1,0,0
  126.  
  127. '   Screen To Front TEMP2
  128.    Screen TEMP2
  129.    Cls 0 : Rem very important look at note below -->  
  130.  
  131. '
  132. ' ** amos Icons/Bobs are all on Word Boundarys... that is why
  133. '    you can't figure out the length of a line of an icon by just using  
  134. '    (x2-x1)... so if you grabbed a icon of width 50 that takes
  135. '    at leats 4 words (4*16=64 --> 64-50=extra 14 pixels/line) 
  136. '    that is why you need the cls 0 so that the extra room gets
  137. '    filled with a zero therefore masking out the data...
  138. '
  139.    X_SIZE=Deek(Icon Base(_ICON)) : Rem x-size of icon in words
  140.    LINE_LEN=(X_SIZE*16) : Rem size of one line in mask in pixels 
  141. '
  142. ' have to be able to have an exact number of line_lengths across in  
  143. ' the linear mask screen.. ie. if the lenght of one line of the mask 
  144. ' is 48 then say _page_width=320 --> 320 mod 48=32 then linear mask
  145. ' screen width should be _page_width-32=320-32=288... need this because
  146. ' you are grabbling the mask linearly from memory so if there is blank 
  147. ' space's they wreck the mask... 
  148. '
  149. _T=WID mod LINE_LEN
  150. _LINEAR_MASK_WID=WID-_T
  151. Screen Open TEMP2,_LINEAR_MASK_WID,HIT,2,Lowres : Curs Off : Cls 0 : Screen Hide TEMP2
  152. 'Screen Show TEMP2 
  153.  
  154. '
  155. ' need to copy the screen data into the mask.. but amos screws up  
  156. ' screens that are not at multiples of 16 in width so can't make a 
  157. ' small screen then just copy the whole bitplane directly into 
  158. ' the mask so this next bit just writes out screen data linearly 
  159. ' across the screen so that it is possible to copy from the bitplane 
  160. ' to get the mask data...  
  161. '
  162.    XP=0 : YP=0
  163.    For X=1 To(Y2-Y1)
  164.       Screen Copy TEMP1,0,X-1,0+LINE_LEN,X To TEMP2,XP,YP
  165.       XP=XP+LINE_LEN
  166.        If(XP/LINE_LEN) mod(_LINEAR_MASK_WID/LINE_LEN)=0 : Inc YP : XP=0 : End If 
  167.    Next 
  168.  
  169.    _MASK_LENGTH=Leek(Icon Base(-_ICON))-4
  170.    _MASK_ADDR=Icon Base(-_ICON)+4
  171.  
  172.    Copy Phybase(0),Phybase(0)+_MASK_LENGTH To _MASK_ADDR
  173.  
  174.    'Print Hex$(Phybase(0)),X_SIZE,_MASK_LENGTH,Hex$(_MASK_ADDR) 
  175.    'Wait Key  
  176.  
  177.    Screen Close TEMP1
  178.    Screen Close TEMP2
  179.  
  180. Screen _T_SCR : Rem set the current screen back..
  181.  
  182.  
  183. '********* 
  184. '
  185. End Proc